﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsForms;

using System.Data.SqlClient;

namespace 空气质量检测
{
    public partial class Lurujcsj : Form
    {

        DBHelper db = new DBHelper();
        DataSet ds = new DataSet();

        public Lurujcsj()
        {
            InitializeComponent();
        }

        private void Lurujcsj_Load(object sender, EventArgs e)
        {

            db.OpenConnection();

            string str = "select * from StationInfo";
            SqlDataAdapter adapter = new SqlDataAdapter(str,db.Connection);
            adapter.Fill(ds, "StationInfo");


            this.comboBox1.DataSource = ds.Tables["StationInfo"];
            this.comboBox1.ValueMember = "StationID";
            this.comboBox1.DisplayMember = "StationNamer";


            db.CloseConnection();

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = null;
            this.textBox2.Text = null;
            this.textBox3.Text = null;
            this.textBox4.Text = null;
            this.textBox5.Text = null;
            this.textBox6.Text = null;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (this.textBox1.Text.Trim().Equals(string.Empty) || this.textBox2.Text.Trim().Equals(string.Empty)
                || this.textBox3.Text.Trim().Equals(string.Empty) || this.textBox4.Text.Trim().Equals(string.Empty)
                || this.textBox5.Text.Trim().Equals(string.Empty) || this.textBox6.Text.Trim().Equals(string.Empty) ) {

                MessageBox.Show("请将信息填完整！");
                return;
            }

            db.OpenConnection();
            string str = "Insert into AirQualityInfo(StationID,InputName,StartDate,EndDa,PM,Level,Notes)values(N'"+this.comboBox1.SelectedValue+"',N'"+this.textBox1.Text+ "',N'" + this.textBox2.Text + "',N'" + this.textBox3.Text + "',N'" + this.textBox4.Text + "',N'" + this.textBox6.Text + "',N'" + this.textBox5.Text + "')";
            SqlCommand comm = new SqlCommand(str,db.Connection);
            int iRet = comm.ExecuteNonQuery();

            if (iRet > 0)
            {
                MessageBox.Show("添加成功！");
            }
            else {
                MessageBox.Show("添加失败！");
            }
            db.CloseConnection();

        }
    }
}
